home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / bin / setupcon < prev    next >
Encoding:
Text File  |  2007-04-10  |  8.0 KB  |  307 lines

  1. #!/bin/sh
  2.  
  3. #     setupcon -- setup the font and keyboard on the Linux console
  4. #     Copyright ┬⌐ 1999,2000,2001,2002,2003,2006 Anton Zinoviev
  5.  
  6. #     This program is free software; you can redistribute it and/or modify
  7. #     it under the terms of the GNU General Public License as published by
  8. #     the Free Software Foundation; either version 2 of the License, or
  9. #     (at your option) any later version.
  10.  
  11. #     This program is distributed in the hope that it will be useful,
  12. #     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #     GNU General Public License for more details.
  15.  
  16. #     If you have not received a copy of the GNU General Public License
  17. #     along with this program, write to the Free Software Foundation, Inc.,
  18. #     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  
  20. # The same as /usr/bin/which - in order to make "which" available before
  21. # /usr is mounted
  22. which () {
  23.     local IFS
  24.     IFS=:
  25.     for i in $PATH; do
  26.     if [ -x "$i/$1" ]; then
  27.         echo "$i/$1"
  28.         return 0
  29.     fi
  30.     done
  31.     return 1
  32. }
  33.  
  34. while [ "$1" ]; do
  35.     case "$1" in
  36.     -k|--keyboard-only)
  37.         keyboard_only=yes
  38.         ;;
  39.     -f|--font-only)
  40.         font_only=yes
  41.         ;;
  42.     -v|--verbose)
  43.         verbose_option=yes
  44.         ;;
  45.     --force)
  46.         force=yes
  47.         ;;
  48.     --save)
  49.         save=yes
  50.         ;;
  51.     --save-only)
  52.         force=yes
  53.         save=yes
  54.         save_only=yes
  55.         ;;
  56.     -h|--help)
  57.         cat >&2 <<EOF
  58. Usage: setupcon [OPTION] [VARIANT]
  59. Sets up the font and the keyboard on Linux console.
  60.  
  61.   -k, --keyboard-only  setup the keyboard only, do not setup the font
  62.   -f, --font-only      setup the font only, do not setup the keyboard
  63.       --force          do not check whether we are on the console
  64.   -v, --verbose        explain what is being doing, try it if s.t. goes wrong
  65.       --save           copy the font and the ACM in /etc/console-setup,
  66.                          update /etc/console-setup/boottime.kmap.gz
  67.       --save-only      only save; don't setup keyboard/font immediately
  68.   -h, --help           display this help and exit
  69.  
  70. If VARIANT is not specified setupcon looks for the configuration files
  71. (in this order) ~/.console-setup and /etc/default/console-setup.  When
  72. a VARIANT is specified then setupcon looks for the configuration files
  73. ~/.console-setup.VARIANT and /etc/default/console-setup.VARIANT.
  74. EOF
  75.         exit 0
  76.         ;;
  77.     -*)
  78.         echo "setupcon: Unrecognised option $1" >&2
  79.         exit 1
  80.         ;;
  81.     *)
  82.         if [ -z "$VARIANT" ]; then
  83.         VARIANT="$1"
  84.         else
  85.         echo "setupcon: Two variants specified: $VARIANT and $1" >&2
  86.         exit 1
  87.         fi
  88.         ;;
  89.     esac
  90.     shift
  91. done
  92.  
  93. if [ "$VARIANT" ]; then
  94.     USER_CONFIG=${HOME}/.console-setup."$VARIANT"
  95.     MAIN_CONFIG=/etc/default/console-setup."$VARIANT"
  96. else
  97.     USER_CONFIG=${HOME}/.console-setup
  98.     MAIN_CONFIG=/etc/default/console-setup
  99. fi
  100.  
  101. if [ -f "$USER_CONFIG" ]; then
  102.     CONFIG="$USER_CONFIG"
  103. elif [ -f "$MAIN_CONFIG" ]; then
  104.     CONFIG="$MAIN_CONFIG"
  105. else
  106.     echo "setupcon: None of $MAIN_CONFIG nor $USER_CONFIG exists." >&2
  107.     exit 1
  108. fi
  109.  
  110. . "$CONFIG"
  111.  
  112. if [ "$verbose_option" = yes ]; then
  113.     VERBOSE_OUTPUT=yes
  114. fi
  115. if [ "$VERBOSE_OUTPUT" = yes ]; then
  116.     verbose=''
  117. else
  118.     verbose='>/dev/null 2>&1'
  119. fi
  120.  
  121. if which ckbcomp-mini >/dev/null && [ "$CHARMAP" != UTF-8 ]; then
  122.     CHARMAP=UTF-8
  123.     if [ "$VERBOSE_OUTPUT" = yes ]; then
  124.     echo Only UTF-8 is supported by console-setup-mini
  125.     fi
  126. fi
  127.  
  128. if [ "$force" != yes ]; then
  129.     case `readlink /proc/self/fd/2` in
  130.     /dev/tty[0-9]*|/dev/vc/[0-9]*|/dev/console)
  131.         ;;
  132.     *)
  133.         if [ "$VERBOSE_OUTPUT" = yes ]; then
  134.         echo We are not on the Linux console, exiting.
  135.         fi
  136.         exit 0 
  137.         ;;
  138.     esac
  139. fi
  140.  
  141. #-----------------------#
  142. #       OUTPUT          #
  143. #-----------------------#
  144.  
  145. if [ "$keyboard_only" != yes ] && [ "$ACTIVE_CONSOLES" ]; then
  146.     for console in $ACTIVE_CONSOLES; do
  147.     [ -w $console ] || continue
  148.     # Setup unicode/non-unicode mode
  149.     if [ "$save_only" != yes ]; then
  150.         if [ "$CHARMAP" = UTF-8 ] || [ -z "$ACM$CHARMAP" ]; then
  151.         /bin/echo -n -e '\033%G' >$console
  152.         else
  153.         /bin/echo -n -e '\033%@' >$console
  154.         fi
  155.     fi
  156.  
  157.     # Load the font
  158.     if [ ! -f "$FONT" ]; then
  159.         for dir in \
  160.         /etc/console-setup \
  161.         /usr/local/share/consolefonts \
  162.         /usr/share/consolefonts
  163.         do
  164.           if [ -f "$dir/$CODESET-$FONTFACE$FONTSIZE.psf.gz" ]; then
  165.           FONT="$dir/$CODESET-$FONTFACE$FONTSIZE.psf.gz"
  166.           case "$FONTSIZE" in
  167.               *x*)
  168.               bigfont=yes
  169.               ;;
  170.               *)
  171.               bigfont=no
  172.               ;;
  173.           esac
  174.           break
  175.           fi
  176.         done
  177.     fi
  178.     if [ -f "$FONT" ]; then
  179.         if \
  180.         [ "$save" = yes ] \
  181.         && [ "${FONT%/*}" != /etc/console-setup ]
  182.         then
  183.         cp "$FONT" /etc/console-setup/
  184.         fi
  185.     else
  186.         if which ckbcomp-mini >/dev/null; then
  187.         FONT=$(echo `ls /usr/share/consolefonts/$CODESET-*.psf.gz \
  188.                                  2>/dev/null`)
  189.         FONT=${FONT%% *}
  190.         if [ -z "$FONT" ]; then
  191.             FONT="$CODESET-$FONTFACE$FONTSIZE.psf.gz"
  192.         fi
  193.         else
  194.         FONT="$CODESET-$FONTFACE$FONTSIZE.psf.gz"
  195.         fi
  196.         case "$FONTSIZE" in
  197.         *x*)
  198.             bigfont=yes
  199.             ;;
  200.         *)
  201.             bigfont=no
  202.             ;;
  203.         esac
  204.     fi
  205.     if [ "$save_only" != yes ]; then
  206.         if which consolechars >/dev/null; then
  207.         if [ "$bigfont" = yes ]; then
  208.             echo "setupcon: The console-chars utility from the console-setup font can load only fonts witn 8 pixel width matrix.  Please install the setfont utility from the kbd package." >&2
  209.         fi
  210.         eval consolechars -v --tty=$console -f "$FONT" $verbose
  211.         elif which setfont >/dev/null; then
  212.         eval setfont -v -C $console "$FONT" $verbose
  213.         fi
  214.     fi
  215.  
  216.     # Load the ACM
  217.     if [ ! -f "$ACM" ]; then
  218.         for dir in \
  219.         /etc/console-setup \
  220.         /usr/local/share/consoletrans \
  221.         /usr/share/consoletrans
  222.         do
  223.           if [ -f "$dir/$CHARMAP.acm.gz" ]; then
  224.           ACM="$dir/$CHARMAP.acm.gz"
  225.           break
  226.           fi
  227.         done
  228.     fi
  229.     if [ -f "$ACM" ]; then
  230.         if \
  231.         [ "$save" = yes ] \
  232.         && [ "${ACM%/*}" != /etc/console-setup ]
  233.         then
  234.         cp "$ACM" /etc/console-setup/
  235.         fi
  236.     else
  237.         ACM="$CHARMAP.acm.gz"
  238.     fi
  239.     if [ "$save_only" != yes ] && [ "$CHARMAP" != UTF-8 ]; then
  240.         if which consolechars >/dev/null; then
  241.         eval consolechars -v --tty=$console --acm "$ACM" $verbose
  242.         elif which setfont >/dev/null; then
  243.         eval setfont -v -C $console -m "$ACM" $verbose
  244.         fi        
  245.     fi
  246.     done
  247. fi
  248.  
  249. #-----------------------#
  250. #        INPUT          #
  251. #-----------------------#
  252.  
  253. if [ "$font_only" != yes ] && [ "$ACTIVE_CONSOLES" ]; then
  254.     # On Mac PPC machines, we may need to set kernel vars first.  We need
  255.     # to mount /proc to do that, but we need it set up before sulogin may
  256.     # be run in checkroot, which will need the keyboard to log in...
  257.     # This code was borrowed from the keymap.sh script of console-common
  258.     # Copyright ┬⌐ 2001 Yann Dirson
  259.     # Copyright ┬⌐ 2001 Alcove http://www.alcove.fr/
  260.     if [ "$save_only" != yes ] && \
  261.        [ -x /sbin/sysctl ] && [ -r /etc/sysctl.conf ]; then
  262.     if grep -v '^\#' /etc/sysctl.conf | grep -q keycodes ; then
  263.         grep keycodes /etc/sysctl.conf | grep -v "^#" \
  264.         | while read d ; do
  265.               /sbin/sysctl -w $d 2> /dev/null || true
  266.               done
  267.     fi
  268.     fi
  269.     
  270.     if [ "$save_only" != yes ]; then
  271.     for console in $ACTIVE_CONSOLES; do
  272.         [ -w $console ] || continue
  273.         if which kbd_mode >/dev/null; then
  274.         if [ "$CHARMAP" = UTF-8 ] || [ -z "$ACM" ]; then
  275.             kbd_mode -u <$console
  276.         else
  277.             kbd_mode -a <$console
  278.         fi    
  279.         fi
  280.     done
  281.     fi
  282.     
  283.     if which loadkeys >/dev/null; then
  284.     if which ckbcomp >/dev/null; then
  285.         if [ "$CHARMAP" != UTF-8 ]; then
  286.         acm_option="-charmap $CHARMAP"
  287.         else
  288.         acm_option=''
  289.         fi
  290.         if [ "$save_only" != yes ]; then
  291.         ckbcomp $acm_option -model "$XKBMODEL" \
  292.             "$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" \
  293.             | eval loadkeys $verbose
  294.         fi
  295.         if which gzip >/dev/null && [ "$save" = yes ]; then
  296.         ckbcomp $acm_option -model "$XKBMODEL" \
  297.             "$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" \
  298.             | gzip -9 >/etc/console-setup/boottime.kmap.gz
  299.         fi
  300.     elif [ "$save_only" != yes ] && \
  301.          [ -f /etc/console-setup/boottime.kmap.gz ]; then
  302.         eval loadkeys /etc/console-setup/boottime.kmap.gz $verbose
  303.     fi
  304.     fi
  305. fi
  306.  
  307.